<?php
$flg = $_POST["flg"];
if($flg == "read"){
	if(!file_exists($_POST["file"])){
		echo "";
		exit;
	}
	$file = fopen($_POST["file"],"r");
	$filemsg = "";
	while (!feof($file)) {
		$line = fgets($file);
		$filemsg .= $line;
	}
	fclose($file);
	echo $filemsg;
}else if($flg == "write"){
	$file = fopen($_POST["file"],"w+");
	if(fwrite($file,$_POST["msg"])){
		fclose($file);
		echo "ok";
	}else{
		echo "error";
	}
}
?>